package lhdx15;

import lhdx13.B;

public class Computer {
    private String ComputerBrand;
    private int price;
    private String colour;
    private String screenSize;
    private boolean starUp = false;//判断是否启动？
    private boolean format = false;//判断是否格式化?
    private boolean lnstallationSystem = false;//判断是否安装操作系统？
    private int diskCapacity;
   // int j = 0;
    // int n = 0;
    Disk[] a = new Disk[0];

    public Computer(String computerBrand, int price, String colour, String screenSize, boolean starUp, boolean format, boolean lnstallationSystem, int diskCapacity) {
        this.ComputerBrand = computerBrand;
        this.price = price;
        this.colour = colour;
        this.screenSize = screenSize;
        this.starUp = starUp;
        this.format = format;
        this.lnstallationSystem = lnstallationSystem;
        this.diskCapacity = diskCapacity;
    }

    public String getComputerBrand() {
        return ComputerBrand;
    }

    public void setComputerBrand(String computerBrand) {
        ComputerBrand = computerBrand;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getColour() {
        return colour;
    }

    public void setColour(String colour) {
        this.colour = colour;
    }

    public String getScreenSize() {
        return screenSize;
    }

    public void setScreenSize(String screenSize) {
        this.screenSize = screenSize;
    }

    public boolean isStarUp() {
        return starUp;
    }

    public void setStarUp(boolean starUp) {
        this.starUp = starUp;
    }

    public boolean isFormat() {
        return format;
    }

    public void setFormat(boolean format) {
        this.format = format;
    }

    public boolean isLnstallationSystem() {
        return lnstallationSystem;
    }

    public void setLnstallationSystem(boolean lnstallationSystem) {
        this.lnstallationSystem = lnstallationSystem;
    }

    public int getDiskCapacity() {
        return diskCapacity;
    }

    public void setDiskCapacity(int diskCapacity) {
        this.diskCapacity = diskCapacity;
    }

    public void purchase() {
        System.out.println("购买新电脑，新电脑信息如下：");
        System.out.println("品牌是：" + ComputerBrand + ",价格：" + price + "分辨率：" + screenSize + "颜色是" + colour + "，磁盘容量：" + diskCapacity + "兆");
    }

    public boolean starup1() {
        System.out.println("启动成功！");
        return starUp = true;
    }

    public void formats(String[] drive, int[] diskSize) {
        if (starUp == true) {
            a = new Disk[drive.length];
            for (int i = 0; i < a.length; i++) {
                if (diskCapacity >= diskSize[i]) {
                    a[i] = new Disk(drive[i], diskSize[i]);
                    diskCapacity = diskCapacity - diskSize[i];
                } else {
                    System.out.println("磁盘容量不够！");
                    return;
                }
            }
            format = true;
            System.out.println("格式化成功！");
            return;
        } else
            System.out.println("请启动！ ");
    }

    public boolean lnstallationSystems(String drive, SystemsSoftware B) {
        if (starUp == true && format == true) {
            for (int i = 0; i < a.length; i++) {
                if (a[i].getDrive().equals(drive)) {//找到所要安装的盘符??????????////
                    if (a[i].getDiskSize() >= B.getSize()) {//磁盘空间要大于等于软件大小；
                        a[i].add(B);
                        a[i].setDiskSize(a[i].getDiskSize() - B.getSize());
                        lnstallationSystem = true;
                        System.out.println("安装成功！大小为" + B.getSize() + "兆");
                        return true;
                    } else {
                        System.out.println("磁盘空间不够！");
                        return false;
                    }
                }
            }
            System.out.println("没有这个盘！");
            return false;
        }
        System.out.println("请启动或格式化！");
        return false;
    }

    public void see(String drive) {
        if (starUp == true && format == true && lnstallationSystem == true) {
            for (int i = 0; i < a.length; i++) {
                if (a[i].getDrive().equals(drive)) {
                    System.out.println("安装软件如下：");
                    for (int k = 0; k < a[i].getJ(); k++) {
                        System.out.println(a[i].so[k].toString());
                    }
                    return;
                }
            }
            System.out.println("没有这个盘！");
            return;
        }
        System.out.println("操作错误！");
        return;
    }

    public boolean download(String drive, Software B) {
        if (starUp == true && format == true && lnstallationSystem == true) {
            for (int i = 0; i < a.length; i++) {
                if (a[i].getDrive().equals(drive)) {//找到所要安装的盘符??/
                    if (a[i].getDiskSize()>=B.getSize()){//判断内存是否足够？？？
                        if (B instanceof GeneralSoftware) {//安装什么样的软件???
                            a[i].add((GeneralSoftware) B);
                            a[i].setDiskSize(a[i].getDiskSize() - B.getSize());
                            System.out.println("安装成功!");
                            return true;
                        } if (B instanceof DownloadASoftware){
                            a[i].add((DownloadASoftware)B);
                            a[i].setDiskSize(a[i].getDiskSize() - B.getSize());
                            System.out.println("安装成功!");
                            return true;
                        }
                    }else {
                        System.out.println("磁盘空间不够!");
                        return false;
                    }
                }
            }
            System.out.println("没有这个盘！");
            return false;
        }
        System.out.println("操作错误！");
        return false;
    }
}
